package com.zzyl.nursing.controller.member;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDTO;

import com.zzyl.nursing.service.IMemberReservationService;
import com.zzyl.nursing.vo.TimeCountVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/member/reservation")
public class MemberReservationController extends BaseController {
    @Autowired
    private IMemberReservationService memberReservationService;


    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        System.out.println("------" + userId);
        return R.ok(0);
    }

    //查询每个时间段剩余预约次数
    @GetMapping("/countByTime")
    public R<List<TimeCountVo>> countByTime(Long time) {
        List<TimeCountVo> list = memberReservationService.getCountByTime(time);
        return R.ok(list);
    }

    //新增预约
    @PostMapping()
    public R addReservation(@RequestBody ReservationDTO reservationDTO) {
        memberReservationService.addReservation(reservationDTO);
        return R.ok();
    }

    // 分页查询预约
    @GetMapping("/page")
    public AjaxResult list(ReservationDTO reservationDTO) {
        startPage();
        List<Reservation> list = memberReservationService.selectReservationList(reservationDTO);
        return success(getDataTable(list));

    }

    //取消预约
    @PutMapping("/{id}/cancel")
    public R cancel(@PathVariable Long id) {
        memberReservationService.removeById(id);
        return R.ok();
    }

}
